/* * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hookedonplay.decoviewsample;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;

public class MainAbility extends Ability implements Component.ClickedListener {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        (findComponentById(ResourceTable.Id_btn_case_0)).setClickedListener(this);
        (findComponentById(ResourceTable.Id_btn_case_1)).setClickedListener(this);
        (findComponentById(ResourceTable.Id_btn_case_2)).setClickedListener(this);
        (findComponentById(ResourceTable.Id_btn_case_3)).setClickedListener(this);
        (findComponentById(ResourceTable.Id_btn_case_4)).setClickedListener(this);
        (findComponentById(ResourceTable.Id_btn_case_5)).setClickedListener(this);
        (findComponentById(ResourceTable.Id_btn_case_6)).setClickedListener(this);
        (findComponentById(ResourceTable.Id_btn_case_7)).setClickedListener(this);
        (findComponentById(ResourceTable.Id_btn_case_8)).setClickedListener(this);
        (findComponentById(ResourceTable.Id_btn_case_9)).setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        Intent intent = new Intent();
        Operation operation = null;
        switch (component.getId()) {
            case ResourceTable.Id_btn_case_0:
                operation = new Intent.OperationBuilder().withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(DecoAbility.class.getSimpleName())
                        .build();
                break;
            case ResourceTable.Id_btn_case_1:
                operation = new Intent.OperationBuilder().withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(SampleFitAbility.class.getSimpleName())
                        .build();
                break;
            case ResourceTable.Id_btn_case_2:
                operation = new Intent.OperationBuilder().withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(SampleFit2Ability.class.getSimpleName())
                        .build();
                break;
            case ResourceTable.Id_btn_case_3:
                operation = new Intent.OperationBuilder().withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(SampleInterpolatorsMainAbility.class.getSimpleName())
                        .build();
                break;
            case ResourceTable.Id_btn_case_4:
                operation = new Intent.OperationBuilder().withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(Sample3Ability.class.getSimpleName())
                        .build();
                break;
            case ResourceTable.Id_btn_case_5:
                operation = new Intent.OperationBuilder().withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(SamplePeopleAbility.class.getSimpleName())
                        .build();
                break;
            case ResourceTable.Id_btn_case_6:
                operation = new Intent.OperationBuilder().withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(Sample2Ability.class.getSimpleName())
                        .build();
                break;
            case ResourceTable.Id_btn_case_7:
                operation = new Intent.OperationBuilder().withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(Sample1Ability.class.getSimpleName())
                        .build();
                break;
            case ResourceTable.Id_btn_case_8:
                operation = new Intent.OperationBuilder().withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(Sample4Ability.class.getSimpleName())
                        .build();
                break;
            case ResourceTable.Id_btn_case_9:
                operation = new Intent.OperationBuilder().withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(SamplePauseAbility.class.getSimpleName())
                        .build();
                break;
        }
        intent.setOperation(operation);
        startAbility(intent);
    }
}